using System;
using System.Data;
using System.Data.SQLite;
using System.IO;
using Firestarter.DB.Schema.Logic;
using Habanero.Base;
using Habanero.DB;

namespace Firestarter.DB.Schema.Test.Logic
{
    public class TestUtilsDB_SQLite : TestUtilsDB
    {
        private IDatabaseConnection _masterDatabaseConnection;

        public override DatabaseConfig CreateTestDatabaseConfig()
        {
            return new DatabaseConfig("SQLite", "", TestDatabaseName + ".db", "", "", null);
        }

        protected override DatabaseConfig CreateMasterDatabaseConfig()
        {
            throw new NotImplementedException();
        }

        public override CreateTableSqlBuilder CreateSqlBuilderCreateTable(string tableName)
        {
            return new CreateTableSqlBuilder_SQLite(tableName);
        }

        public override void CreateTestDatabase()
        {
            // just copy the file since SQLLite is a file-based database.
            try
            {
                string databaseFileName = TestDatabaseName + ".db";
                if (File.Exists(databaseFileName)) File.Delete(databaseFileName);
                var templateDbName = "Schema_test_source.db";
                if (!File.Exists(templateDbName))
                {

                    SQLiteConnection.CreateFile(templateDbName);
                }
                File.Copy(templateDbName, databaseFileName);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }

        public override void ClearDatabase(IDbConnection connection) { throw new NotImplementedException(); }
        public override void DropDatabase()
        {
            throw new NotImplementedException();
        }
    }
}